/**
 * @filename:PromptConfigServiceImpl 2025-05-14
 * @project starhub-schema  V1.0
 */
package com.starhub.engine.prompt.service.impl;

import com.starhub.common.sys.user.LoginUser;
import com.starhub.engine.generator.genid.IdGenerator;
import com.starhub.engine.prompt.entity.PromptConfig;
import com.starhub.engine.prompt.dao.PromptConfigDao;
import com.starhub.engine.prompt.service.PromptConfigService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.*;
import java.util.stream.Collectors;

/**   
 * @Description:(提示词设置服务实现)
 *
 * @version: V1.0
 * @author: luosw
 * 
 */
@Service
public class PromptConfigServiceImpl implements PromptConfigService {
    @Autowired
    private PromptConfigDao promptDao;

    /**
    * 新增
    * @param user
    * @param prompt
    * @return
    */
    public Long add(LoginUser user, PromptConfig prompt){

        Long id = IdGenerator.generateId();

        //数据封装，默认值添加
        prompt.setId(id);
        prompt.setCreateTime(new Date());
        prompt.setUpdateTime(new Date());
        prompt.setDeleteType(0);

        promptDao.insertSelective(prompt);
        return id;
    }

    /**
    * 更新
    * @param user
    * @param prompt
    * @return
    */
    public PromptConfig update(LoginUser user, PromptConfig prompt){
        prompt.setUpdateTime(new Date());
        //不允许更新的属性设置为null
        promptDao.updateByPrimaryKeySelective(prompt);
        return prompt;
    }

    /**
    * 基本信息获取
    * @param user
    * @param id
    * @return
    */
    public PromptConfig getInfo(LoginUser user, Long id){

        PromptConfig prompt = promptDao.selectByPrimaryKey(id);
        return prompt;
    }

    /**
    * (批量)删除，同时支持单条或者批量,此方法为逻辑删除
    * @param user
    * @param ids
    */
    public void deleteByType(LoginUser user, String ids,int deleteType){

        //数组转换
        List<Long> idList = Arrays.stream(ids.split(","))
            .map((id) -> Long.parseLong(id))
            .collect(Collectors.toList());
            //删除状态，目前只有1的逻辑
        promptDao.deletePromptConfigByType(idList, deleteType);
    }

    /**
    * 根据id删除，此方法为真实删除
    * @param user
    * @param ids
    */
    public void deleteRecord(LoginUser user, String ids){

        //数组转换
        List<Long> idList = Arrays.stream(ids.split(","))
            .map((id) -> Long.parseLong(id))
            .collect(Collectors.toList());
        promptDao.deletePromptConfigRecord(idList);
    }

    /**
    * 列表查询
    * @param user
    * @param params
    */
    public List<PromptConfig> getList(LoginUser user,  Map<String , Object>  params){

        List<PromptConfig> promptList =  new ArrayList<PromptConfig>();
            //TODO
        int pageSize = 10;
        int current = 1;
        PromptConfig record = new PromptConfig();
        record.setDeleteType(0);
        promptList = promptDao.selectByPrimaryKeySelective(record);
        return promptList;
    }


}